home *** CD-ROM | disk | FTP | other *** search
- /* Abstract syntax tree
- *
- * SOFTWARE RIGHTS
- *
- * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
- * Set (PCCTS) -- PCCTS is in the public domain. An individual or
- * company may do whatever they wish with source code distributed with
- * PCCTS or the code generated by PCCTS, including the incorporation of
- * PCCTS, or its output, into commerical software.
- *
- * We encourage users to develop software with PCCTS. However, we do ask
- * that credit is given to us for developing PCCTS. By "credit",
- * we mean that if you incorporate our source code into one of your
- * programs (commercial product, research project, or otherwise) that you
- * acknowledge this fact somewhere in the documentation, research report,
- * etc... If you like PCCTS and have developed a nice tool with the
- * output, please mention that you developed it using PCCTS. In
- * addition, we ask that this header remain intact in our source code.
- * As long as these guidelines are kept, we expect to continue enhancing
- * this system and expect to make other tools available as they are
- * completed.
- *
- * ANTLR 1.31
- * Terence Parr
- * Parr Research Corporation
- * with Purdue University and AHPCRC, University of Minnesota
- * 1989-1995
- */
-
- #ifndef PCCTSAST_H
- #define PCCTSAST_H
-
- #include <stdio.h>
- #include <stdlib.h>
- #include "config.h"
- class List;
-
- #define StringScanMaxText 50
- #define MaxTreeStackDepth 400
-
- typedef struct stringlexer {
- signed int c;
- char *input;
- char *p;
- char text[StringScanMaxText];
- } StringLexer;
-
- /* Define the structures needed for ast_scan() */
- typedef struct stringparser {
- int token;
- StringLexer *lexer;
- int num_labels;
- } StringParser;
-
- typedef struct _scanast {
- struct _scanast *right, *down;
- int token;
- int label_num;
- } ScanAST;
-
- #define VALID_SCAN_TOKEN(t) (t>=LPAREN && t<=PERIOD)
-
- class PCCTS_AST {
- protected:
- static char *scan_token_tbl[];
- unsigned const LPAREN=1;
- unsigned const RPAREN=2;
- unsigned const PERCENT=3;
- unsigned const INT=4;
- unsigned const COLON=5;
- unsigned const POUND=6;
- unsigned const PERIOD=7;
- const StringScanEOF=-1;
-
- protected:
- char *scan_token_str(int t);
- void stringlexer_init(StringLexer *scanner, char *input);
- void stringparser_init(StringParser *, StringLexer *);
- ScanAST *stringparser_parse_scanast(char *templ, int *n);
- ScanAST *stringparser_parse_tree(StringParser *parser);
- ScanAST *stringparser_parse_element(StringParser *parser);
- void stringscan_advance(StringLexer *scanner);
- int stringscan_gettok(StringLexer *scanner);
- void _push(PCCTS_AST **st, int *sp, PCCTS_AST *e);
- PCCTS_AST *_pop(PCCTS_AST **st, int *sp);
- int match_partial(PCCTS_AST *t, PCCTS_AST *u);
- int scanmatch(ScanAST *t, PCCTS_AST **labels[], int *n);
- void scanast_free(ScanAST *t);
- ScanAST *new_scanast(int tok);
- void stringparser_match(StringParser *parser, int token);
-
- public:
- PCCTS_AST() {;}
- virtual ~PCCTS_AST() {;}
-
- /* This group must be defined for SORCERER to work correctly */
- virtual PCCTS_AST *right() = 0;
- virtual PCCTS_AST *down() = 0;
- virtual void setRight(PCCTS_AST *t) = 0;
- virtual void setDown(PCCTS_AST *t) = 0;
- virtual int token() { return 0; } // we define these so ANTLR doesn't have to
- virtual void setToken(int t) {;}
-
- /* These are not needed by ANTLR, but are support functions */
- virtual void addChild(PCCTS_AST *t);
- virtual void lisp_action(FILE *f) {;}
- virtual void lisp(FILE *f);
- static PCCTS_AST *make(PCCTS_AST *rt, ...);
- virtual PCCTS_AST *find_all(PCCTS_AST *t, PCCTS_AST *u, PCCTS_AST **cursor);
- virtual int match(PCCTS_AST *t, PCCTS_AST *u);
- virtual void insert_after(PCCTS_AST *a, PCCTS_AST *b);
- virtual void append(PCCTS_AST *a, PCCTS_AST *b);
- virtual PCCTS_AST *tail(PCCTS_AST *a);
- virtual PCCTS_AST *bottom(PCCTS_AST *a);
- virtual PCCTS_AST *cut_between(PCCTS_AST *a, PCCTS_AST *b);
- virtual List *to_slist(PCCTS_AST *t);
- virtual void tfree(PCCTS_AST *t);
- virtual int ast_scan(char *templ, ...);
- virtual int nsiblings(PCCTS_AST *t);
- virtual PCCTS_AST *sibling_index(PCCTS_AST *t, int i);
-
- require(int e,char *err){ if ( !e ) panic(err); }
- virtual panic(char *err){ fprintf(stderr, "PCCTS_AST: %s\n", err); exit(1); }
- };
-
- #endif /* PCCTSAST_H */
-